'use strict';

module.exports = app => {
  const {
    INTEGER,
    STRING,
    DATE,
  } = app.Sequelize;
  const ReceivingAddress = app.model.define('receivingaddress', {
    id: {
      type: INTEGER,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
      comment: '序号',
    },
    consignee: {
      type: STRING(30),
      allowNull: false,
      comment: '收货人',
    },
    province: {
      type: STRING(50),
      allowNull: false,
      comment: '省',
    },
    city: {
      type: STRING(50),
      allowNull: false,
      comment: '市',
    },
    county: {
      type: STRING(50),
      allowNull: false,
      comment: '县',
    },
    street: {
      type: STRING(50),
      allowNull: false,
      comment: '街道/镇',
    },
    detailed: {
      type: STRING(200),
      allowNull: false,
      comment: '详细地址',
    },
    tel: {
      type: STRING(20),
      allowNull: false,
      comment: '手机号码',
    },
    email: {
      type: STRING(50),
      comment: '邮箱',
    },
    address_alias: {
      type: STRING(50),
      comment: '地址别名',
    },
    default_address: {
      type: INTEGER(2),
      allowNull: false,
      comment: '是否是默认地址，1 表示是，反之',
    },
    uid: {
      type: INTEGER,
      allowNull: false,
      comment: '用户ID对应关系',
    },
    createdDate: {
      type: DATE,
      allowNull: false,
      comment: '创建时间',
      field: 'createdDate',
    },
    updatedDate: {
      type: DATE,
      allowNull: false,
      comment: '更改时间',
      field: 'updatedDate',
    },
  }, {
    freezeTableName: true,
    timestamps: false, // 去除createAt updateAt
  });
  ReceivingAddress.associate = function() {
    app.model.Receivingaddress.belongsTo(app.model.User, {
      foreignKey: 'uid',
      targetKey: 'id',
    });
  };
  return ReceivingAddress;
};
